﻿<?php
    error_reporting(0);
    session_start();
    //数据库连接
    $conn=mysql_connect('localhost','root','root');
    mysql_select_db('itxmgl',$conn);
    //定义常量
  define(ALL_PS,"PHP");

  // if($_POST[submit]){
    // $username= str_replace(" ","",$_POST[username]);
    $jsonData= json_encode($_POST); 
    $objData=json_decode($jsonData);
    $username=$objData->{'username'}; 
    $password=$objData->{'password'};
   // $code=$objData->{'code'};


    $sql="select * from r_customer where `username` = '$username'";
    $query=mysql_query($sql);
    $us=is_array($row=mysql_fetch_array($query));
    // $ps= $us ? md5($_POST[password].ALL_PS)== $row[password] : FALSE;
    $ps= $us ? md5($password.ALL_PS)== $row[password] : FALSE;

    // if($ps&&$_POST[code]== $_SESSION["code"]){
   // if($ps&&$code== $_SESSION["code"])
   if($ps){
      // echo "登陆成功";
      //这里返回给前端一个json状态标识$isLoginSuccess
      $_SESSION["username"]=$username;
      $tempArr = array('isLoginSuccess'=>true,'username'=>$_SESSION['username']);
      $backData = json_encode($tempArr); 
      echo $backData; 

    }else{
        $tempArr = array('isLoginSuccess'=>false,'username'=>$username);
        $backData = json_encode($tempArr); 
        echo $backData; 

        session_destroy();
    }

  // }
  

    
?>
